<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>修改昵称</title>
    <link rel="stylesheet" href="__ASSETS__/share/css/nickname.css"/>
</head>
<body>
    <form class="regBox" action="{:U('User/nickname')}">
    <div class="login_box">
        <div class="head">
            <div class="logo">
                <img src="__ASSETS__/share/images/logo.png">
            </div>
        </div>
        <div class="login">
            <div class="login-head">
                修改昵称
                <img src="__ASSETS__/share/images/cat1.png" class="cat" alt=""/>
            </div>
            <div class="input-login">
                <div class="input-box">
                    <div class="input input-nickname">
                        <i></i>
                        <input type="text" placeholder="请修改昵称" name="nickname" class="nickname JS_input" onkeyup="test()" value="{$sso_nickname}" />
                    </div>
                    <div class="msg"></div>
                    <div class="login-btn">
                        <button type="button" class="JS_submit">确认</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </form>
    <div class="footer">
        <p>©2013 All Rights Reserved.版权所有.成都映霸龙渊网络科技有限公司</p>
        <p>公司地址：成都高新区府城大道399号天府新谷5号楼1204</p>
    </div>
</body>
<script src="__ASSETS__/share/js/jquery-1.8.2.min.js"></script>
<script>
    function test(){
        $(".input span").remove();
        var nickname = $(".nickname").val();
        var myreg =/[`~!@#$%^&*()_+<>?:"{},.\/;'[\]]/im;
        var s=myreg.test(nickname);
        if(s){
            $(".input").append("<span class='wrong'></span>");
            $(".msg").html("昵称不合法，请不要输入特殊字符！");
        }else{
            $(".input").append("<span class='right'></span>");
            $(".msg").empty();
            $.ajax({
                url:"http://test.66play.com/api/visitor/checkNickname?nickname="+nickname+"",
                type:'get',
                dataType:'json',
                success:function(data){
                    $(".input span").remove();
                    if(data.code==200){
                        $(".input").append("<span class='right'></span>");
                    }else{
                        $(".input").append("<span class='wrong'></span>");
                    }
                    $(".msg").html(data.info);
                }
            });
        }

    }

var redirect_url = '{$redirect_url}' || '/';
$('.JS_submit').click(function(){
    $.ajax({
        url:$('form').attr('action'),
        data:$(".JS_input").serialize(),
        type:'post',
        dataType:'json',
        success:function(data){
            if(data.state < 0){
                alert(data.info)
                return;
            }else{
                window.location.href= redirect_url;
            }
        }
    });
});
</script>
</html>